<?php
App::import('Vendor', 'PHPMailer', array('file' => 'php_mailer' . DS . 'PHPMailerAutoload.php'));

/**
 *
 */
class PHPMailerComponent extends Object
{

    public function sendMail($from,$to,$subject,$body,$html = false){

        $mail = new PHPMailer;

        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'smtp.gmail.com';                       // Specify main and backup server
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = 'infosmsgoldgh@gmail.com';                   // SMTP username
        $mail->Password = 'adminnimda';               // SMTP password
        $mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
        $mail->Port = 587;                                    //Set the SMTP port number - 587 for authenticated TLS
        $mail->setFrom($from['email'], $from['name']);     //Set who the message is to be sent from
        //$mail->addReplyTo('labnol@gmail.com', 'First Last');  //Set an alternative reply-to address
        //$mail->addAddress('josh@example.net', 'Josh Adams');  // Add a recipient
        $mail->addAddress($to);                                 // Name is optional
       // $mail->addCC('cc@example.com');
       // $mail->addBCC('bcc@example.com');
        $mail->WordWrap = 50;                                 // Set word wrap to 50 characters
       // $mail->addAttachment('/usr/labnol/file.doc');         // Add attachments
       // $mail->addAttachment('/images/image.jpg', 'new.jpg'); // Optional name
        $mail->isHTML($html);                                  // Set email format to HTML

        $mail->Subject = $subject;
        $mail->Body    = $body;
       // $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

        //Read an HTML message body from an external file, convert referenced images to embedded,
        //convert HTML into a basic plain-text alternative body
        //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));

        if(!$mail->send()) {
            return array('status'=>false,'message'=>'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo);
        }
        else{
            return array('status'=>true,'message'=>'Message has been sent');
        }

    }

    public function initialize()
    {

    }

    public function startup()
    {

    }

    public function beforeRender()
    {

    }

    public function beforeRedirect()
    {

    }

    public function shutdown()
    {

    }
}